﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;
using Antu.Core.DataAccess;

namespace WebSys.UI.Control.ZhengShou
{
    public class CompensationBasicInIframeControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            Button btn_Insert = (Button)FindControl("btn_Insert");
            btn_Insert.Click += new EventHandler(btn_Insert_Click);
            TextBox txt征收部门 = (TextBox)FindControl("txt征收部门");
            TextBox txt征收实施单位 = (TextBox)FindControl("txt征收实施单位");
            TextBox txt开户银行 = (TextBox)FindControl("txt开户银行");
            TextBox txt银行账号 = (TextBox)FindControl("txt银行账号");
            TextBox txt评估总补偿款 = (TextBox)FindControl("txt评估总补偿款");
            TextBox txt到账金额 = (TextBox)FindControl("txt到账金额");
            TextBox txt划转金额 = (TextBox)FindControl("txt划转金额");
            TextBox txt余额 = (TextBox)FindControl("txt余额");
            MPCalendar txt时间 = (MPCalendar)FindControl("txt时间");
            TextBox txt备注 = (TextBox)FindControl("txt备注");
            TextBox txt说明 = (TextBox)FindControl("txt说明");
            TextBox txtPNID = (TextBox)FindControl("txtPNID");
            TextBox txtID = (TextBox)FindControl("txtID");
            TextBox LXH = (TextBox)FindControl("LXH");
            string strPid = base.Page.Request["PID"];
            string strid = base.Page.Request["ID"];
            if (!base.Page.IsPostBack)
            {
                if (!string.IsNullOrEmpty(strPid))
                {
                    if (string.IsNullOrEmpty(txtPNID.Text.Trim())) { txtPNID.Text = strPid; }
                    EluZSProvider.Project project = _EluZSDataProvider.GetProjectXX(strPid);
                    LXH.Text = project.立项号;
                    txt征收部门.Text = project.征收部门;
                    txt征收实施单位.Text = project.征收实施单位;
                }
                if (!string.IsNullOrEmpty(strid))
                {
                    txtID.Text = strid;
                    EluZSProvider.Bcbasicinfo bcbasicinfo = _EluZSDataProvider.GetBcbasicinfo(strid);
                    txt开户银行.Text = bcbasicinfo.开户银行;
                    txt银行账号.Text = bcbasicinfo.银行账号;
                    txt评估总补偿款.Text = bcbasicinfo.评估总补偿款;
                    txt到账金额.Text = bcbasicinfo.到账金额;
                    txt划转金额.Text = bcbasicinfo.划转金额;
                    txt余额.Text = bcbasicinfo.余额; 
                    if (bcbasicinfo.时间.HasValue) { txt时间.Text = bcbasicinfo.时间.Value.ToShortDateString(); }
                    txt备注.Text = bcbasicinfo.备注;
                    txt说明.Text = bcbasicinfo.说明;
                    txtPNID.Text = bcbasicinfo.PNID;
                    txtID.Text = bcbasicinfo.ID;
                }
                else
                {
                    txtID.Text = System.Guid.NewGuid().ToString().Replace("-", "");
                }
            }
        }
        protected void btn_Insert_Click(object sender, EventArgs e)
        {
            TextBox txt征收部门 = (TextBox)FindControl("txt征收部门");
            TextBox txt征收实施单位 = (TextBox)FindControl("txt征收实施单位");
            TextBox txt开户银行 = (TextBox)FindControl("txt开户银行");
            TextBox txt银行账号 = (TextBox)FindControl("txt银行账号");
            TextBox txt评估总补偿款 = (TextBox)FindControl("txt评估总补偿款");

            TextBox txt到账金额 = (TextBox)FindControl("txt到账金额");
            TextBox txt划转金额 = (TextBox)FindControl("txt划转金额");
            TextBox txt余额 = (TextBox)FindControl("txt余额");
            MPCalendar txt时间 = (MPCalendar)FindControl("txt时间");
            TextBox txt备注 = (TextBox)FindControl("txt备注");

            TextBox txt说明 = (TextBox)FindControl("txt说明");
            TextBox txtPNID = (TextBox)FindControl("txtPNID");
            TextBox txtID = (TextBox)FindControl("txtID");
            string strid = base.Page.Request["ID"];
            string strPid = base.Page.Request["PID"];
            EluZSProvider.Bcbasicinfo bcbasicinfo = new EluZSProvider.Bcbasicinfo();
            bcbasicinfo.征收部门 = txt征收部门.Text.Trim(); 
            bcbasicinfo.征收实施单位 = txt征收实施单位.Text.Trim(); 
            bcbasicinfo.开户银行 = txt开户银行.Text.Trim(); 
            bcbasicinfo.银行账号 = txt银行账号.Text.Trim(); 
            bcbasicinfo.评估总补偿款 = txt评估总补偿款.Text.Trim(); 

            bcbasicinfo.到账金额 = txt到账金额.Text.Trim(); 
            bcbasicinfo.划转金额 = txt划转金额.Text.Trim(); 
            bcbasicinfo.余额 = txt余额.Text.Trim();
            bcbasicinfo.时间 = (string.IsNullOrEmpty(txt时间.Text) ? null : (DateTime?)Convert.ToDateTime(txt时间.Text));
            bcbasicinfo.备注 = txt备注.Text.Trim(); 

            bcbasicinfo.说明 = txt说明.Text.Trim(); 
            bcbasicinfo.PNID = txtPNID.Text.Trim(); 
            bcbasicinfo.ID = txtID.Text.Trim(); 
            bool save = _EluZSDataProvider.SaveBcbasicinfo(strid, bcbasicinfo);
            if (save) { base.Page.Response.Write("<script>alert('保存成功！');window.location.href('CompensationBasicInIframe.aspx?ID="+txtID.Text+"&PID="+strPid+"');</script>"); }
        }
    }
}


